import { ref, computed } from 'vue';
import { defineStore } from 'pinia';

export const useMainStore = defineStore('main', () => {
  const backgroudColor = ref<Record<string, string>>({});
  const fontColor = ref<Record<string, string>>({});
  const fixRow = ref<Set<any>>(new Set());
  const focusRefresh = ref(Date.now());
  const lastBackgroundColor = ref('');
  const lastFontColor = ref('');
  const rowHeight = ref(38);
  const getBackgroundColor = (id: string, col: number) => {
    return backgroudColor.value[id + ':' + col];
  };

  const getFontColor = (id: string, col: number) => {
    return fontColor.value[id + ':' + col];
  };

  const setBackgroundColor = (id: string, col: number, color?: string) => {
    backgroudColor.value[id + ':' + col] = color!;
    lastBackgroundColor.value = color!;
  };

  const setFontColor = (id: string, col: number, color?: string) => {
    fontColor.value[id + ':' + col] = color!;
    lastFontColor.value = color!;
  };

  return {
    rowHeight,
    fixRow,
    focusRefresh,
    lastBackgroundColor,
    lastFontColor,
    getFontColor,
    getBackgroundColor,
    setFontColor,
    setBackgroundColor,
  };
});
